<template>
  <div class="navbar">
    <div class="hamburger-container" @click="toggleClick">
      <el-icon size="18">
        <component :is="$icon[iconStatus]"></component>
      </el-icon>
    </div>
    <div class="right-menu">
      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
        <div class="avatar-wrapper">
          <span>您好，{{ name }}</span>
          <el-icon>
            <component :is="$icon['CaretBottom']"></component>
          </el-icon>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>
              <span style="display: block" @click="logout">退出系统</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {removeUserStorage} from "@/utils/setStorage";
import router from "@/routes/router";
import {ref} from "vue";
import {useUserStore} from "@/stores";

const name = ref<string>('')
const iconStatus = ref<string>('Expand')
name.value = useUserStore().userData.user_name

const logout = () => {
  removeUserStorage()
  router.push({name: 'login'})
}
const isActive = ref<boolean>(false)
const toggleClick = () => {
  isActive.value = !isActive.value
  isActive.value ? iconStatus.value = 'Fold' : iconStatus.value = 'Expand'
}
</script>

<style lang="scss" scoped>
.svg-icon {
  vertical-align: middle;
}

.is-active {
}

.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

  .list-status {

  }

  .hamburger-container {
    line-height: 50px;
    float: left;
    padding: 0 15px;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: flex;
      align-items: center;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>